using System;

namespace B.S.NewMedical.Api.Read.DTOS.Patient
{
    /// <summary>
    /// 患者显示DTO
    /// </summary>
    public class PatientDisplayDto
    {
        /// <summary>
        /// 患者ID
        /// </summary>
        public int Id { get; set; }

        /// <summary>
        /// 用户Id（关联用户账号）
        /// </summary>
        public int? AccountId { get; set; }

        /// <summary>
        /// 姓名
        /// </summary>
        public string? Name { get; set; }

        /// <summary>
        /// 性别（true=男，false=女）
        /// </summary>
        public bool? Sex { get; set; }

        /// <summary>
        /// 性别显示文本
        /// </summary>
        public string? SexText => Sex.HasValue ? (Sex.Value ? "男" : "女") : "未设置";

        /// <summary>
        /// 出生日期
        /// </summary>
        public DateTime? DateOfBirth { get; set; }

        /// <summary>
        /// 年龄（计算得出）
        /// </summary>
        public int? Age 
        { 
            get 
            {
                if (DateOfBirth.HasValue)
                {
                    var today = DateTime.Today;
                    var age = today.Year - DateOfBirth.Value.Year;
                    if (DateOfBirth.Value.Date > today.AddYears(-age))
                        age--;
                    return age;
                }
                return null;
            }
        }

        /// <summary>
        /// 联系方式
        /// </summary>
        public string? ContactInfo { get; set; }

        /// <summary>
        /// 身份证号（脱敏显示）
        /// </summary>
        public string? IDCard { get; set; }

        /// <summary>
        /// 身份证号（脱敏处理）
        /// </summary>
        public string? IDCardMasked 
        { 
            get 
            {
                if (string.IsNullOrWhiteSpace(IDCard) || IDCard.Length < 8)
                    return IDCard;
                
                // 显示前6位和后4位，中间用*代替
                return IDCard.Substring(0, 6) + "********" + IDCard.Substring(IDCard.Length - 4);
            }
        }

        /// <summary>
        /// 现居地址
        /// </summary>
        public string? CurrentAddress { get; set; }

        /// <summary>
        /// 传染病史
        /// </summary>
        public string? InfectiousDiseaseHistory { get; set; }

        /// <summary>
        /// 遗传病信息
        /// </summary>
        public string? GeneticDiseaseInfo { get; set; }

        /// <summary>
        /// 创建人
        /// </summary>
        public string? CreatePeople { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime? CreateTime { get; set; }

        /// <summary>
        /// 更新人
        /// </summary>
        public string? UpdatePeople { get; set; }

        /// <summary>
        /// 更新时间
        /// </summary>
        public DateTime? UpdateTime { get; set; }
    }
}